public class Workfor5 {
    public static void main(String[] args) {
        int wellDepth = 7;
        int climbByDay = 3;
        int slipByNight = 2;

        int days = calculateDays(wellDepth, climbByDay, slipByNight);
        System.out.println("青蛙需要 " + days + " 天才能爬出 " + wellDepth + " 米深的井");
    }

    // 简洁版计算方法
    public static int calculateDays(int wellDepth, int climbByDay, int slipByNight) {
        int currentHeight = 0;
        int days;

        // 使用for循环，但实际上是while的替代用法
        for (days = 1; ; days++) {
            currentHeight += climbByDay;  // 白天爬升

            if (currentHeight >= wellDepth) {
                break;  // 如果爬出井，结束循环
            }

            currentHeight -= slipByNight;  // 晚上滑下
        }

        return days;
    }
}